from rest_framework import viewsets
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from dqjj.server.server import Server


# Create your views here.
class DqjjViewSet(viewsets.ModelViewSet):
    # 指定权限类， 要求用户认证
    permission_classes = [IsAuthenticated]

    # 注入服务
    server = Server()

    def get_area_select_list(self, request):
        # 时间查询入参times，数据遵循国家数据时间筛选入参格式。
        datas = self.server.area_dqjj_select_list()

        return Response(datas)

    def get_area_dqjj(self, request):
        times = request.query_params.get('times', '2022')
        types = request.query_params.get('type')
        datas = self.server.area_dqjj_datas(type=types, times=times)
        return Response(datas)
